package com.nuanshui.heatedloan.msgcenter.model;

import com.nuanshui.heatedloan.dal.IdTypeHandler;
import com.nuanshui.heatedloan.msgcenter.integration.AppPushMsgBody;
import com.nuanshui.heatedloan.msgcenter.integration.UserDeviceTokenVo;

import java.util.HashMap;
import java.util.List;


public class AppPushMessage {

    private List<HashMap<String, Object>> userTokens = null;//推送的用户token

    private AppPushMsgBody msgBody;

    public AppPushMsgBody getMsgBody() {
        return msgBody;
    }

    public void setMsgBody(AppPushMsgBody msgBody) {
        this.msgBody = msgBody;
    }

    public List<HashMap<String, Object>> getUserTokens() {
        return userTokens;
    }

    public void setUserTokens(List<HashMap<String, Object>> userTokens) {
        this.userTokens = userTokens;
    }

    public static UserDeviceTokenVo convertToken(HashMap<String, Object> userToken)
    {
        UserDeviceTokenVo item=new UserDeviceTokenVo();
        //badge
        int badge =  Integer.valueOf(String.valueOf(userToken.get("num")));
        item.setBadge(badge);

        //userToken
        String deviceToken =(String) userToken.get("device_token");
        item.setDeviceToken(deviceToken);

        //deviceType
        String deviceType =(String) userToken.get("device_type");
        item.setDeviceType(deviceType);

        //userId
        item.setUserId((long) userToken.get("userId"));

        item.setDstUserId(IdTypeHandler.encode(item.getUserId()));
        return item;
    }
}
